package com.example.boot.dubbo.consumer;

import com.example.dubbo.common.bean.User;
import com.example.dubbo.common.service.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class BootDubboConsumerApplication {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @DubboReference(url = "dubbo://127.0.0.1:12345")
    private UserService userService;

    public static void main(String[] args) {
        SpringApplication.run(BootDubboConsumerApplication.class).close();
    }

    @Bean
    public ApplicationRunner runner() {
        return args -> {
            logger.info("BootDubboConsumer.add --> {}", userService.add(new User(null, "boot-dubbo", 15)));
            logger.info("BootDubboConsumer.get --> {}", userService.get(1));
        };
    }
}
